package sys.knot.model;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sys.knot.data.access.NamedDataSource;
import sys.knot.interpreter.ResultSetInterpreter;

import java.util.List;

public class QuerySpecification {

    private Logger logger = LoggerFactory.getLogger(QuerySpecification.class);

    private String name;
    private String sql;
    private List<QueryParameter> orderedQueryParameters;
    private ResultSetInterpreter resultSetInterpreter;
    private List<NamedDataSource> dataSources;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSql() {
        return sql;
    }

    public void setSql(String sql) {
        this.sql = sql;
    }

    public List<QueryParameter> getOrderedQueryParameters() {
        return orderedQueryParameters;
    }

    public void setOrderedQueryParameters(List<QueryParameter> orderedQueryParameters) {
        this.orderedQueryParameters = orderedQueryParameters;
    }

    public ResultSetInterpreter getResultSetInterpreter() {
        try {
            return resultSetInterpreter.getClass().newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            //TODO handle nicer...
            RuntimeException rte = new RuntimeException("Could not instantiate resultSetInterpreter", e);
            logger.error(rte.getMessage(), rte);
            throw rte;
        }
    }

    public void setResultSetInterpreter(ResultSetInterpreter resultSetInterpreter) {
        this.resultSetInterpreter = resultSetInterpreter;
    }

    public List<NamedDataSource> getDataSources() {
        return dataSources;
    }

    public void setDataSources(List<NamedDataSource> dataSources) {
        this.dataSources = dataSources;
    }
}
